package com.ktgj.customer.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ktgj.common.core.annotation.Excel;
import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.common.core.utils.DateUtils;
import com.ktgj.customer.domain.Employee;
import com.ktgj.customer.domain.TravelSupplierDto;
import com.ktgj.customer.domain.vo.TravelSupplierVo;
import com.ktgj.customer.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.TravelSupplierMapper;
import com.ktgj.customer.domain.TravelSupplier;
import com.ktgj.customer.service.ITravelSupplierService;

import javax.servlet.http.HttpServletRequest;

/**
 * 供应商Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@Service
public class TravelSupplierServiceImpl implements ITravelSupplierService 
{
    @Autowired
    private TravelSupplierMapper travelSupplierMapper;
    @Autowired
    private ILoginService loginService;

    /**
     * 查询供应商
     * 
     * @param supplierId 供应商ID
     * @return 供应商
     */
    @Override
    public TravelSupplierDto selectTravelSupplierById(Long supplierId)
    {
        return travelSupplierMapper.selectTravelSupplierById(supplierId);
    }

    /**
     * 查询供应商列表
     * 
     * @param travelSupplierDto 供应商
     * @return 供应商
     */
    @Override
    public List<TravelSupplierDto> selectTravelSupplierList(TravelSupplierDto travelSupplierDto)
    {
        return travelSupplierMapper.selectTravelSupplierList(travelSupplierDto);
    }

    /**
     * 新增供应商
     * 
     * @param travelSupplierDto 供应商
     * @return 结果
     */
    @Override
    public int insertTravelSupplier(TravelSupplierDto travelSupplierDto)
    {
        travelSupplierDto.setCreateTime(DateUtils.getNowDate());
        return travelSupplierMapper.insertTravelSupplier(travelSupplierDto);
    }

    /**
     * 修改供应商
     * 
     * @param travelSupplierDto 供应商
     * @return 结果
     */
    @Override
    public int updateTravelSupplier(TravelSupplierDto travelSupplierDto)
    {
        return travelSupplierMapper.updateTravelSupplier(travelSupplierDto);
    }

    /**
     * 批量删除供应商
     * 
     * @param supplierIds 需要删除的供应商ID
     * @return 结果
     */
    @Override
    public int deleteTravelSupplierByIds(Long[] supplierIds)
    {
        return travelSupplierMapper.deleteTravelSupplierByIds(supplierIds);
    }

    /**
     * 删除供应商信息
     * 
     * @param supplierId 供应商ID
     * @return 结果
     */
    @Override
    public int deleteTravelSupplierById(Long supplierId)
    {
        return travelSupplierMapper.deleteTravelSupplierById(supplierId);
    }

    /**
     * 供应商列表
     * */
    @Override
    public List<TravelSupplierVo> travelSupplierVoList(String supplierName){
        TravelSupplierDto travelSupplierDto = new TravelSupplierDto();
        if (supplierName != null && !supplierName.equals("")){
            travelSupplierDto.setSupplierName(supplierName);
        }
        List<TravelSupplierVo> travelSupplierVos = travelSupplierMapper.queryTravelSupplierList(travelSupplierDto);
        return travelSupplierVos;
    }

    /**
     * 新增供应商
     * */
    @Override
    public int addTravelSupplier(HttpServletRequest request, TravelSupplier travelSupplier) throws Exception {
        Date date = new Date();
        Employee loginEmployee = loginService.getLoginEmployee(request);
        if (loginEmployee == null){
            throw new Exception("登录已过期");
        }

        travelSupplier.setEmployeeId(loginEmployee.getEmployeeId());
        travelSupplier.setEmployeeName(loginEmployee.getEmployeeName());
        travelSupplier.setCreateTime(date);

        int i = travelSupplierMapper.addTravelSupplier(travelSupplier);
        return i;
    }

    /**
     * 修改供应商
     * */
    @Override
    public int updTravelSupplier(TravelSupplier travelSupplier) {
        int i = travelSupplierMapper.updTravelSupplier(travelSupplier);
        return i;
    }

    /**
     * 团供应商列表
     * */
    @Override
    public List<TravelSupplier> groupSupplierList() {
        List<TravelSupplier> travelSupplierList = travelSupplierMapper.groupSupplierList();
        return travelSupplierList;
    }
}
